package com.ccp.dev.system.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.system.dao.SysObjRightsDao;
import com.ccp.dev.system.model.SysObjRights;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 对象权限 信息操作服务类
 *
 * @author hw
 * @date 2019-09-25 20:22:42
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysObjRightsService extends BaseService<SysObjRights> {

    @Resource
    private SysObjRightsDao sysObjRightsDao;

    /**
     * 先根据ObjectId进行删除相应的数据,然后再依次进行保存
     * @param sysObjRightsList
     * @return
     */
    public int save(List<SysObjRights> sysObjRightsList){
        if(sysObjRightsList.size() > 0){
            this.sysObjRightsDao.deleteByObjectId(sysObjRightsList.get(0).getObjectId());
        }
        int result = 0;
        for (SysObjRights sysObjRights:sysObjRightsList) {
            sysObjRights.setId(UUIDUtils.getUUIDFor32());
            result += this.sysObjRightsDao.add(sysObjRights);

        }
        return result;
    }
}
